﻿@model IndoReputation.Views.ViewModels.NewsViewModel

@{
    ViewBag.Title = "Edit News";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Edit News</h2>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.mcdropdown.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.bgiframe.js")" type="text/javascript"></script>
@using (Html.BeginForm()) {
    @Html.ValidationSummary(false)
    <fieldset>
        @Html.HiddenFor(model => model.ID)
        @Html.HiddenFor(model => model.CreateAt)
        @Html.HiddenFor(model => model.CreateBy)
        @{ Html.Telerik().TabStrip()
        .Name("TabStrip")
        .Items(parent =>
        {
            parent.Add()
            .Text("General Information")
            .Content(
            @<text>
            <div class="form-data">
                <table class="table-data">
                    <tr>
                        <td class="td-label">
                            <div class="editor-label">
                                @Html.LabelFor(model => model.MediaID, null, true)
                            </div>
                        </td>
                        <td class="td-control">
                            <div class="editor-field">
                                @( Html.Telerik().ComboBoxFor(model => model.MediaID)
                                        .Name("MediaID")
                                        .BindTo(new SelectList(Model.Media, "Value", "Text"))
                                        .Placeholder("Select News Media ")
                                        .SelectedIndex(0)
                                        .Filterable(filtering =>
                                        {
                                            filtering.FilterMode(AutoCompleteFilterMode.Contains);
                                        })
                                        .HighlightFirstMatch(true)
                                        .ClientEvents(events => events.OnChange("ComboBox_onChange").OnLoad("ComboBox_onLoad"))
                                     )
                                @Html.ValidationMessageFor(model => model.MediaID)
                                @Html.HiddenFor(model => model.MediaName)
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td class="td-label">
                            <div class="editor-label">
                                @Html.LabelFor(model => model.MediaCategory)
                            </div>
                        </td>
                        <td class="td-control">
                            <div class="editor-field">
                                @Html.TextBoxFor(model => model.MediaCategory, new { @readonly = "readonly" })       
                                @Html.Partial("~/Views/Shared/EditorTemplates/Flag.cshtml")
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td class="td-label">
                            <div class="editor-label">
                                @Html.LabelFor(model => model.DatePublished, null, true)
                            </div>
                        </td>
                        <td class="td-control">
                            <div class="editor-field">
                                @(Html.Telerik().DatePickerFor(model => model.DatePublished)
                                    .Name("DatePublished")
                                    .Value((DateTime)ViewData["selectedDate"])
                                )
                                @Html.ValidationMessageFor(model => model.DatePublished)
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td class="td-label">
                            <div class="editor-label">
                                @Html.LabelFor(model => model.Title, null, true)
                            </div>
                        </td>
                        <td class="td-control">
                            <div class="editor-field">
                                @Html.EditorFor(model => model.Title)
                                @Html.ValidationMessageFor(model => model.Title)
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td class="td-label">
                            <div class="editor-label">
                                @Html.LabelFor(model => model.Sumary)
                            </div>
                        </td>
                        <td class="td-control">
                            <div class="editor-field">
                                @{Html.Telerik().EditorFor(model => model.Sumary)
                                      .Name("Sumary")
                                      .HtmlAttributes(new { style = "height: 250spx" })
                                      .Encode(true)                      
                                      .Render();
                                  }                
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td class="td-label">
                            <div class="editor-label">
                                @Html.LabelFor(model => model.Link)
                            </div>
                        </td>
                        <td class="td-control">
                            <div class="editor-field">
                                @Html.EditorFor(model => model.Link)
                                @Html.ValidationMessageFor(model => model.Link)
                            </div>
                        </td>
                    </tr>
                </table>
            </div>
            </text>)
            .Selected(true);
            parent.Add()
            .Text("Analyzing And Scoring The News")
            .Content(
            @<text>
            <div class="form-data">
                <table class="table-data">
                    <tr>
                        <td class="td-label">
                            <div class="editor-label">
                                @Html.LabelFor(model => model.NewsCategory, null, true)
                            </div>
                        </td>
                        <td class="td-control">
                            <div class="editor-field">
                                <div class="div-mcdd">
                                    <input type="text" name="category" id="category" value="" />
                                    @(Html.TreeView(Model.ListNewsCategory)
                                    .EmptyContent("No category have been defined yet!")
                                    .Children(m => m.ChildLocations)
                                    .HtmlAttributes(new { id = "categorymenu", @class = "mcdropdown_menu" })
                                    .ChildrenHtmlAttributes(new { @class = "subItem" })
                                    .ItemValue(m => m.ID.ToString())
                                    .ItemText(m => m.Name)                    
                                    )
                                </div>
                                @Html.HiddenFor(model => model.NewsCategory)  
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td class="td-label">
                            @Html.LabelFor(model => model.ListNewsValuesModel, null, true)
                        </td>
                        <td class="td-control"></td>
                    </tr>
                    <tr>
                        <td colspan="2">
                            <div>
                                @Html.EditorFor(model => model.ListNewsValuesModel)
                            </div>
                        </td>
                    </tr>
                </table>
            </div>                                    
            </text>);
        })
        .Effects(fx => fx.Expand()
                         .Opacity()
                         .OpenDuration(200)
                         .CloseDuration(300)
        )
        .SelectedIndex(0)
        .Render();
        }        
        <div class="form-data">
            <table class="table-data">
                <tr>
                 <td class="td-label"></td>
                 <td class="td-control">
                    <p class="dvbutton">
                        <input type="submit" name="btnSubmit" value="Save" />
                        <input type="submit" name="btnSubmit" value="Save & Published" />
                    </p>                    
                 </td>
                </tr>
            </table>
        </div>     
    </fieldset>
}
<div class="div-back">
    @Html.ActionLink("Back to List", "Index")
</div>
@if (false)
{
    <script src="../../Scripts/jquery-1.7.2-vsdoc.js" type="text/javascript"></script>
}
<script type="text/javascript">
    $(document).ready(function () {
        $("#category").mcDropdown("#categorymenu", { allowParentSelect: true, select: changeVal });
        var dd = $("#category").mcDropdown();
        // SET VALUE
        dd.setValue($("#NewsCategory").val(), true);
    });

    function changeVal() {
        var dd = $("#category").mcDropdown();
        var currentVal = dd.getValue();
        currentVal = currentVal + '';
        currentVal = currentVal.split(",");
        $("#NewsCategory").val(currentVal[0]);
    }

    function ComboBox_onLoad() {
        var combobox = $(this).data('tComboBox'); // $(this) is equivalent to $('#ComboBox')
        var _data = {
            'mediaID': combobox.value()
        };
        $.ajax({
            url: '@Url.Action("GetMediaCategoryNameAjax")',
            type: 'POST',
            contentType: 'application/json',
            data: JSON.stringify(_data),
            success: function (result) {
                $("#MediaCategory").val(result.Name);
                if (result.IsNewspaper) {
                    $("#flagMain").attr('style', 'display: inline;');
                    $("#flagMain").attr('src', '../../../Content/img/news2424.png');
                }
                else if (result.IsTV) {
                    $("#flagMain").attr('style', 'display: inline;');
                    $("#flagMain").attr('src', '../../../Content/img/tivi2424.png');
                }
                else if (result.IsRadio) {
                    $("#flagMain").attr('style', 'display: inline;');
                    $("#flagMain").attr('src', '../../../Content/img/radio2424.png');
                }
                else if (result.IsOnlineNews) {
                    $("#flagMain").attr('style', 'display: inline;');
                    $("#flagMain").attr('src', '../../../Content/img/news2424.png');
                }
                else {
                    $("#flagMain").attr('style', 'display: none;');
                }

                if (result.IsOnline) {
                    $("#flagInternet").attr('style', 'display: inline;');
                    $("#flagInternet").attr('src', '../../../Content/img/ie2424.png');
                }
                else {
                    $("#flagInternet").attr('style', 'display: none;');
                }
            }
        });
    }

    function ComboBox_onChange() {
        var combobox = $(this).data('tComboBox');
        $("#MediaName").val(combobox.text());
        var _data = {
            'mediaID': combobox.value()
        };
        $.ajax({
            url: '@Url.Action("GetMediaCategoryNameAjax")',
            type: 'POST',
            contentType: 'application/json',
            data: JSON.stringify(_data),
            success: function (result) {
                $("#MediaCategory").val(result.Name);
                if (result.IsNewspaper) {
                    $("#flagMain").attr('style', 'display: inline;');
                    $("#flagMain").attr('src', '../../../Content/img/news2424.png');
                }
                else if (result.IsTV) {
                    $("#flagMain").attr('style', 'display: inline;');
                    $("#flagMain").attr('src', '../../../Content/img/tivi2424.png');
                }
                else if (result.IsRadio) {
                    $("#flagMain").attr('style', 'display: inline;');
                    $("#flagMain").attr('src', '../../../Content/img/radio2424.png');
                }
                else if (result.IsOnlineNews) {
                    $("#flagMain").attr('style', 'display: inline;');
                    $("#flagMain").attr('src', '../../../Content/img/news2424.png');
                }
                else {
                    $("#flagMain").attr('style', 'display: none;');
                }

                if (result.IsOnline) {
                    $("#flagInternet").attr('style', 'display: inline;');
                    $("#flagInternet").attr('src', '../../../Content/img/ie2424.png');
                }
                else {
                    $("#flagInternet").attr('style', 'display: none;');
                }
            }
        });
    }

    $('form').submit(function () {
        if ($("#NewsCategory").val() == 0) {
            alert("Please choose News Category");
            return false;
        }
    });
</script>